Back to Contents        Previous        Next







6. System variables

‘System variables’ are another important feature of RISCOS and their concept is simple. They are variables which, once created, are available for use by any application running on the computer (i.e. they are ‘super-global’). It is also important to note that, unlike ordinary variables created within your application, system variables do not disappear automatically when you quit your application. They remain until the computer is shut down - unless you take specific steps to delete them.

The most common way to create system variables is by using one of two ‘star commands’ (*Set or *SetEval) in a Command or Obey file. Typically, nearly every application creates at least one system variable in its !Run and/or !Boot file. In addition, Dr Wimp provides a pair of wimp-functions to create/delete system variables from within your program. (Star commands can, of course, also be issued from the command line or Task Window.)

The most important use of system variables takes place largely out of sight. It is the system variable called Obey$Dir which is used in the very important job of making sure that an application can run from anywhere, eg: floppy disc, hard drive, CD, etc, whilst still giving the application the essential access to files in the application directory, eg: templates, sprites, message files, etc.

Whenever the !Run file of any application is run (e.g. by double clicking on the application icon) the Wimp automatically puts the full directory path of that !Run file into Obey$Dir - and this system variable retains that ‘value’ until another application’s !Run file is run (likely to be very soon) or the computer is shut down.

It is standard Wimp practice - usually in the very first line of a !Run file - for an application’s !Run file immediately to copy this ‘value’ of Obey$Dir into a new system variable uniquely named for the application e.g. MyApp$Dir for the application !MyApp. This is done immediately, before there is any opportunity for another application to be run. The programmer can then use MyApp$Dir in the application coding as part of file references to application resources e.g when loading window templates, with full confidence that it points to the right place irrespective of where the application is located or what other applications are started subsequently.


System variables can also be useful for other things. For example, if you wrote an application to process user-supplied data you might have to set the maximum size of the data allowed, but you might also wish to gve the user the option to change this maximum size. The limit could be put in the !Run file as the value of a uniquely named system variable - which will be simple for the user to change.

Please note that all system variable ‘values’ are strings. Further, although there are few restrictions on naming system variables, there are certain conventions detailed in the Style Guide and PRMs. A look inside various application !Run files will soon indicate what is normal.

Dr Wimp provides a small suite of wimp functions to allow you to create, delete, read value of and check existence of system variables from within your application coding - see Section 3.1.







Top of page        Back to Contents        Previous        Next